<#--
	id, 
	path: refresh path
	name : data to show (it's pageInfo object)
	rowClickLinks: click event, show the sub list
	dblClickJs: the js method to process the double-click event
	dblClickPath: the double-click path
	
	Extra variable for internal component:
	_gridModel: different phase for generating the tag (_gridModel: 4/41/42 header, 5 body, 6 advance search template, 9 populate column information(TODO))
	_namePrefix: pageinfo name
	_gridItem: value for generating the tag
	
	_colIndex: current column index
-->
<#macro pageinfo name='' namePrefix='' path='' sort='' dir='' clazz='' style='' model='' collection=[] minWidth=0 paginationClazz=''
	rowClickLinks=[] dblClick='_updateRecord' dblClickPath='' showPagination=true enableSearch=true useWinScrollBar=true showWinBtn=true id=''>
	<#local cid = tag.getCid(name, 'pageinfo')>
	<#assign _namePrefix = tag.pushNamePrefix(action, namePrefix)>
	<#assign pminWidth = minWidth>

	<#-- push ps -->
	<#local shortName = tag.getShortName(name)>
	<#local _ps = ps>
	<#assign ps = ps.checkAddElement(shortName, name, 'pageinfo', {'model':model, 'sort':sort, 'dir':dir})>
	
	<#if ps.length?? && ps.length gt 0>
		<#assign pminWidth = ps.length>
	</#if>
	
	<#-- get pageInfo -->
	<#if collection?size == 0>
		<#assign pageInfo = fn.val(action, _namePrefix)!>
	<#else>
		<#assign pageInfo = collection>
	</#if>
	<#if !pageInfo?? || !pageInfo.totalCount??>
		<#if pageInfo?? && pageInfo?is_collection>
			<#assign pageInfo=fn.newModel('com.googlecode.cswish.model.PageInfo',{'data',pageInfo})>
		<#else>
			<#assign pageInfo=fn.newModel('com.googlecode.cswish.model.PageInfo',{'data',[]})>
		</#if>
	</#if>
	
	<#-- check permission -->
	<#local service = fn.service('loginUser')>
	<#local dblClick = ps.extraParams?if_exists.dblClick!dblClick>
	<#local dblClickPath = fn.linkNoBase(dblClickPath,true)>
	<#local hasPermission = dblClickPath != '' && dblClickPath != '#' && service.hasLinkPermission(dblClickPath, false)>
	<#if !hasPermission>
		<#local dblClick = ''>
	<#else>
		<#local dblClickRecords = service.getRecordPermission(dblClickPath, false, pageInfo.data![])>
	</#if>
	<#local rowClickLinks = fn.linkNoBases(rowClickLinks,true)>
	<#local clickLinks = service.filterLinkPermission(rowClickLinks, true)>
	
	<#-- show the table -->
	<#if path == ''>
		<#local submitAction = fn.getSubmitAction(actionPath)>
		<#local path = fn.linkNoBase(submitAction,true) + '?'>
	<#elseif path?index_of('?') < 0>
		<#local path = fn.linkNoBase(path,true) + '?'>
	</#if>
	<#local tableWidth = fn.tag.css(pminWidth, style, 'width')>
<div id="${id}" class="jpageinfo stdEle stdCtn ${clazz} ${cid}" uiType="pageinfo" style="${style}" name="${shortName}" fullName="${name}"
		 sort="${fn.s(fn.val(action, 'sort'),'sort')!}" dir="${fn.s(fn.val(action, 'dir'),'dir')!}" showWinBtn="${showWinBtn?string}"
		pageSize='${pageInfo.pageSize}' totalCount='${pageInfo.totalCount}' maxPageNo='${pageInfo.maxPageNo}' namePrefix="${_namePrefix}"
		<#if path!=''>path="${base}${path}&_resultCode=$element&_elementName=${name}<#if Parameters._tpl?exists>&_tpl=${Parameters._tpl}</#if>"</#if>
		<#if dblClick != ''>dblClickPath="${base}${dblClickPath}"</#if>
		<#if clickLinks?size gt 0>links="${tag.getPageInfoClickLink(base,clickLinks,'|;|')}" model="${model}"</#if>>
	<#if showPagination>
		<@pagination pageInfo=pageInfo paginationClazz=paginationClazz/>
	</#if>
	<#if showWinBtn && clickLinks?size gt 0 && !ps.getExtraParam('mock')??>
		<div class="ctn-min-icon" onclick="showPageinfoContainer(event,this)" style="right:16px"></div>
		<div class="ctn-max-icon" onclick="showPageinfoContainer(event,this)" style="right:2px"></div>
	</#if>

	<#-- provide default value for better display performance, see jtaglig.js, _adjustTableHeight-->
	<#if pageInfo.data?? && pageInfo.data?size gt 10>
		<#if clickLinks?size gt 1>
			<#local pageinfoListHeight = 235>
		<#elseif clickLinks?size == 1>
			<#local pageinfoListHeight = 350>
		</#if>
	</#if>
	
	<#assign _gridModel=9>
	<@span name="_selectButton" width=25/>
	<#nested>
	
	<#assign _emptyColWidthCount = tag.getEmptyColWidthCount(action, ps)>
	<#assign _colCount = tag.getColCount(action, ps)>
	<#assign _totalColWidth = tag.getTotalColWidth(action, ps)>
	<#assign _colIndex = -1>
	
	<div style="overflow: hidden;"><div class="jpageinfolist" style="<#if pageinfoListHeight??>height:${pageinfoListHeight}px</#if><#if tableWidth !=0>;min-width:${tableWidth}px</#if>">
	<table class="tablelist fullWidth JColResizer"> <#-- NOTICE: don't add namePrefix="${_namePrefix}" avoid formatTableElement-->
		<thead>
		<tr>			
			<#-- don't show the sort flag, show the nested content -->
			<#assign _gridModel=42>
			<@span name="_selectButton" clazz="fixedEle selectAll" width=25><input type="checkbox" onclick="selectAll(this)"/></@span>
			<#-- sort condition: sort path is not blank & data exists -->
			<#if path != '' && pageInfo.data?? && pageInfo.data?size gt 0>
				<#-- show the sort flag, show the readonly text -->
				<#assign _gridModel=4>
			<#else>
				<#-- don't show the sort flag, show the readonly text -->
				<#assign _gridModel=41>
			</#if>
			<#nested>
		</tr>
		</thead>
		
		<#if pageInfo.data?? && pageInfo.data?size gt 0>
		<tbody>
			<#assign _gridModel=5>
			
			<#local pageData = pageInfo.data>
			<#list pageData as item>
				<#assign _gridItem=item>
				<#assign thePrefix = 'results[' + item_index + '].'>
				<#assign modelId = fn.val(item, 'id')!0>
				<#local hasRecordPermission = hasPermission && (dblClickRecords == pageData || dblClickRecords.indexOf(item) >= 0)>
				<tr <#if item_index % 2 == 1>class="even"</#if> modelId="${modelId}" <#if !hasRecordPermission>disableDblClick=true</#if>>
					<@span name="_selectButton">
						<input type=checkbox name="${thePrefix}id" value="${modelId}" onclick="stopEvent(event)" ondblclick="stopEvent(event)"/>
					</@span>
					<#if !pshow><input type=hidden name="${thePrefix}id" value="${modelId}"/></#if>
					
					<#nested>
				</tr>
			</#list>
		</tbody>
		<#else>
		<tbody><tr class="noData"><td colspan="${_colCount}"><@i18n name='没有数据'/></td></tr></tbody>
		</#if>
	</table>
	</div></div>
	
	<#-- search template, used by advance search button-->
	<#if enableSearch>
	<#assign separator1 = path?last_index_of('.')>
	<#assign separator2 = path?last_index_of('.', separator1 - 1)>
	<#assign adSearchPath = path?substring(0, separator2) + '.search' + path?substring(separator1)>
	<div class="searchTemplate" action="${base}${adSearchPath}">
		<div class="searchTemplate-title"><@i18n name='高级查询'/></div>
		<#assign _gridModel=6>
		<#assign _namePrefix = 'model.'>
		<#nested>
		<div style="clear: both"></div>
		<div class="button-search" onclick='advanceSearch(this, "${name}")'><em></em></div>
		<a class="resetCondition" style="color:gray" href="javascript:void(0)" onclick='resetAdvanceSearchForm(event,this)'><@i18n name='重置查询条件'/></a>
		<div class="close" onclick='closeAdvanceSearchMenu(this)'></div>
		
		<div class="expressionTip">
			<div class="leftArrow"></div>
			<div class="close" onclick='closeTipMenu(this)' style="top:0;right:-4px"></div>
			
			<div style="padding-bottom: 5px;"><@i18n name='提示'/></div>
			
			<label><@i18n name='包含'/></label>
			<div class="jbox"><input type="text" name="" class="contain jinput" flag='' onkeyup="addExpression(this, '')" onblur="blurSearchInput(this)"/></div>
			<label><@i18n name='不包含'/></label>
			<div class="jbox"><input type="text" name="" class="not jinput" flag='!'  onkeyup="addExpression(this, '!')" onblur="blurSearchInput(this)"/></div>
			
			<label><@i18n name='从'/></label>
			<div class="jbox"><input type="text" name="" class="larger jinput" flag='&gt;' onkeyup="addExpression(this, '&gt;')" onblur="blurSearchInput(this)"/></div>
			<label><@i18n name='到'/></label>
			<div class="jbox"><input type="text" name="" class="less jinput" flag='&lt;' onkeyup="addExpression(this, '&lt;')" onblur="blurSearchInput(this)"/></div>
		</div>
	</div>
	</#if>
	<#-- search template, end -->
	
	<@script name=cid _inner=true>
		when('initPageinfo', function(){
			<#-- show the selected sort link -->
			initPageinfo(j171('.${cid}'), '${dblClick}', ${(!ps.isMock() && useWinScrollBar)?string}, ${showWinBtn?string}, ${_totalColWidth}, ${_emptyColWidthCount}, ${(ps.getExtraParam('mock')!false)?string});
		});
	</@script>
</div>
	<#assign _gridModel=0>
	<#-- popup ps -->
	<#assign ps = _ps>
	
	<#assign _namePrefix = tag.popNamePrefix(action, namePrefix)>
	
	<@inject name='container.pageinfo' point='header' type='html' once=true>
		<@script src="/static/espirit/scripts/colResizable-1.3.js"/>
		<@script src="/static/espirit/scripts/jquery.fixedheadertable.js"/>
	</@inject>
</#macro>

<#macro tableheader name='' style=''>
	<#local shortName = tag.getShortName(name)>
	<div class="jtableheader stdEle stdCtn" uiType="tableheader"  name="${shortName}" fullName="${name}">
		<table><tbody><tr class='ctnEle'>
			<#assign _gridModel=41>
			<#assign _emptyColWidthCount = 0>
			<#assign _colCount = 0>
			<#assign _totalColWidth = 0>
			<#assign _colIndex = -1>
				
			<th></th><#nested>
			<#assign _gridModel=0>
		</tr></tbody></table>
	</div>
</#macro>